﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 订单窗体
{
    public partial class Form3 : Form
    {
        private OrderService _orderService;
        public List<Order> QueryResult { get; private set; }
        public Form3(OrderService orderService)
        {

            InitializeComponent();
            _orderService = orderService;
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (rbOrderId.Checked)
                {
                    QueryResult = _orderService.QueryByOrderId(txtKeyword.Text);
                }
                else if (rbProductName.Checked)
                {
                    QueryResult = _orderService.QueryByProductName(txtKeyword.Text);
                }
                else if (rbCustomer.Checked)
                {
                    QueryResult = _orderService.QueryByCustomer(txtKeyword.Text);
                }

                if (QueryResult == null || QueryResult.Count == 0)
                {
                    MessageBox.Show("没有找到匹配的订单", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"查询失败: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}

